home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
vp2_409e.szh
/
ARC_A.C
next >
Wrap
Text File
|
1991-07-13
|
20KB
|
685 lines
/*
$Header: arc_a.c 3.3 87/12/12 00:39:38 Bob Exp $
The Conference Mail System
This module was originally written by Bob Hartman
Sysop of FidoNet node 1:132/101
Spark Software, 427-3 Amherst St, CS 2032, Suite 232, Nashua, NH 03061
The Conference Mail System is a complete Echomail processing package. It
is a superset of the original Echomail utilities created by Jeff Rush, and
also contains ideas gleaned from the ARCmail, Renum, oMMM, MGM, and Opus
programs that were created by various software authors.
This program source code is being released with the following provisions:
1. You are free to make changes to this source code for use on your own
machine, however, altered source files may not be distributed without the
consent of Spark Software.
2. You may distribute "patches" or "diff" files for any changes that you
have made, provided that the "patch" or "diff" files are also sent to Spark
Software for inclusion in future releases of the entire package. A "diff"
file for the source archives may also contain a compiled version, provided
it is clearly marked as not being created from the original source code.
No other executable versions may be distributed without the consent of
Spark Software.
3. You are free to include portions of this source code in any program you
develop, providing: a) Credit is given to Spark Software for any code that
may is used, and b) The resulting program is free to anyone wanting to use
it, including commercial and government users.
4. There is NO technical support available for dealing with this source
code, or the accompanying executable files. This source code is provided
as is, with no warranty expressed or implied (I hate legalease). In other
words, if you don't know what to do with it, don't use it, and if you are
brave enough to use it, you're on your own.
Spark Software may be contacted by modem at (603) 888-8179 (node 1:132/101)
on the public FidoNet network, or at the address given above.
To use this code you will need Microsoft C version 4.0, and also Microsoft
Macro Assembler version 4.0.
*/
/*
$Log: arc_a.c $
* Revision 3.3 87/12/12 00:39:38 Bob
* Source code release
*
*/
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fastecho.h"
#define DEBUG 0
extern char *_months[];
extern SEACONFIG config;
extern AREAS_PTR areas[];
extern char board_name[], sysop_name[];
extern int tot_areas;
extern char bbsfile[];
extern char *arc_cmd[];
extern int nread;
extern int arc_args;
extern int last_msg;
extern int high_one;
extern int convert;
extern struct tm *t2;
extern struct _stamp cur_stamp;
extern int *msg_nums;
extern char *holder1;
extern int mail_low, mail_high;
extern int seen_byl;
extern int cminternal;
extern int to_netmail;
extern PACKED p_msg;
extern PKTHDR pkt_hdr;
extern char cur_dir[];
extern char pkt_dir[];
extern char tmpjunk[], tmpjunk1[], tmpjunk2[];
extern unsigned def_attr;
extern int seahome;
extern MSG msg_tmp;
extern char *tfs;
int arc_compat = 1;
int num_arc = -1;
int arc_net[100];
int arc_node[100];
int arc_msg[100];
char *asuffix[] =
{ "SU1", "MO1", "TU1", "WE1", "TH1", "FR1", "SA1", NULL };
char *weekday[] =
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL };
void arc_a ()
{
int err;
char retname[15];
/* First of all do we have any packets to do? */
sprintf (tmpjunk, "%s*.FS$", pkt_dir);
(void) filedir (tmpjunk, 0, retname, 0);
find_old();
zap_old ();
if (retname[0] == '\0')
{
/* We had no packets to ARCmail */
printf ("No packets generated\n");
return;
}
/* Find all of the ARCmail that we already have out there */
/* Get the first one to ARCmail */
(void) filedir (tmpjunk, 0, retname, 0);
while (retname[0])
{
/* Now for each packet ARC it up */
err = arc_to (retname);
if (err)
{
/* This is bad news - we did not finish the packet */
printf ("Errorlevel %d for ARCmail of '%s' - exiting\n", err, retname);
exit (3);
}
/* Now get the next packet name */
(void) filedir (tmpjunk, 0, retname, 0);
}
}
int arc_to (char retname[])
{
int tonet, tonode;
int netdiff, nodediff;
int err, needmsg;
char newname[64];
char arcext[4];
#ifdef IBMC
char tnet[5];
char tnode[5];
#endif
long tt1;
struct tm *tt2;
/* Find out who we were going to */
#ifndef IBMC
sscanf (retname, "%04x%04x", &tonet, &tonode);
#else
sscanf (retname, "%4s%4s", tnet, tnode);
sscanf (tnet, "%04x", &tonet);
sscanf (tnode, "%04x", &tonode);
#endif
#if DEBUG
printf ("filename is '%s' extracted %d/%d\n", retname, tonet, tonode);
#endif
/* Now create the actual new packet name (must end in .PKT) */
tt1 = time(NULL);
tt2 = localtime (&tt1);
sprintf (tmpjunk1, "%s%s", pkt_dir, retname);
errno = 0;
do {
sprintf (newname,"%s%02d%02d%02d%02d.PKT", pkt_dir, tt2->tm_mday,
tt2->tm_hour, tt2->tm_min, tt2->tm_sec);
errno = 0;
(void) rename(tmpjunk1, newname);
++(tt2->tm_sec);
} while (errno==13);
/* Now get the differences in net and node numbers to generate ARCmail */
netdiff = config.net[1] - tonet;
nodediff = config.node[1] - tonode;
printf ("ARCmailing to %d/%d\n", tonet, tonode);
/* Find the extension to use */
needmsg = suffix (tonet, tonode, arcext, 1);
/* Create the new filename */
sprintf (tmpjunk1, "%s%04x%04x.%s", cur_dir, netdiff, nodediff, arcext);
#if DEBUG
printf ("Using filename '%s'\n", tmpjunk1);
#endif
#if DEBUG
printf ("Packet renamed to '%s'\n", newname);
#endif
/* Now actually create the archive */
strcpy (arc_cmd[arc_args], tmpjunk1);
strcpy (arc_cmd[arc_args+1], newname);
/* strcpy (tmpjunk3, arc_cmd[0]);
for (i = 1; i <= arc_args+1; i++)
{
strcat (tmpjunk3, " ");
strcat (tmpjunk3, arc_cmd[i]);
} */
#if DEBUG
printf ("Before ARC call:\n");
printf (" needmsg = '%d'\n", needmsg);
printf (" config.mailpath = '%s'\n", config.mailpath);
printf (" netdiff = %d nodediff = %d\n", netdiff, nodediff);
#endif
err = spawnvp (P_WAIT, arc_cmd[0], arc_cmd);
if (err)
{
/* Ooops */
sprintf (tmpjunk1, "%s%s", pkt_dir, retname);
#if DEBUG
printf ("ARC error\n Trying to rename %s to %s\n", newname, tmpjunk1);
#endif
(void) rename (newname, tmpjunk1);
return (err);
}
#if DEBUG
printf ("After ARC call:\n");
printf (" needmsg = '%d'\n", needmsg);
printf (" config.mailpath = '%s'\n", config.mailpath);
printf (" netdiff = %d nodediff = %d\n", netdiff, nodediff);
#endif
/* create a file attach message */
if (seahome)
sprintf (tmpjunk1, "%04x%04x.%s", netdiff, nodediff, arcext);
do_attach (needmsg, tonet, tonode, tmpjunk1);
/* If we completed with no errors then unlink the packet */
unlink (newname);
/* Return that all was ok */
return (0);
}
void do_attach (
int msg_no,
int tonet,
int tonode,
char filename[])
{
int f;
char fname1[64];
char *p1;
FILE *fin;
#if DEBUG
printf ("Doing file attach message\n");
#endif
if (cminternal)
{
if (!msg_no)
return;
/* Set up the .FLO filename */
sprintf (fname1, "%s%04x%04x.FLO", cur_dir, tonet, tonode);
if ((fin = fopen (fname1, "a")) == NULL)
{
printf ("Cannot open '%s' - exiting\n", fname1);
exit (2);
}
fprintf (fin, "#%s\n", filename);
fclose (fin);
}
else
{
memset ((char *) &msg_tmp, 0, sizeof (MSG));
strcpy (msg_tmp.from, "ARCmail");
strcpy (msg_tmp.to, "SysOp");
strcpy (msg_tmp.subj, filename);
/* Convert it to uppercase */
p1 = msg_tmp.subj;
while (*p1)
{
*p1 = (char) toupper (*p1);
++p1;
}
sprintf (msg_tmp.date, "%3.3s %2d %3.3s %02d %02d:%02d",
weekday[t2->tm_wday], t2->tm_mday, _months[t2->tm_mon],
t2->tm_year, t2->tm_hour, t2->tm_min);
msg_tmp.date[8] = (char) tolower (msg_tmp.date[8]);
msg_tmp.date[9] = (char) tolower (msg_tmp.date[9]);
msg_tmp.times = 0;
msg_tmp.dest = tonode;
msg_tmp.orig = config.node[1];
msg_tmp.cost = 0;
msg_tmp.orig_net = config.net[1];
msg_tmp.dest_net = tonet;
msg_tmp.reply = 0;
msg_tmp.attr = MSGLOCAL|MSGPRIVATE|MSGFILE|MSGKILL|def_attr;
msg_tmp.up = 0;
msg_tmp._date_written.date = 0;
msg_tmp._date_written.time = 0;
msg_tmp._date_arrived.date = 0;
msg_tmp._date_arrived.time = 0;
/* Create the message file name */
sprintf (fname1, "%s\\%d.MSG", config.mailpath, msg_no);
#if DEBUG
printf ("placing it in '%s'\n", fname1);
#endif
/* Open up new message file */
if((f = open (fname1, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE)) == -1)
{
printf ("\n'%s' could not be opened for file attach - exiting\n", fname1);
exit (2);
}
/* Write out the header information */
(void )fast_write (f, (char *) &msg_tmp, sizeof (MSG));
/* Write out the kludge information */
(void )fast_write (f, tfs, strlen (tfs+1));
/* Now close the file */
(void) fast_close (f);
}
}
int suffix (
int tonet,
int tonode,
char arcext[],
int del)
{
int i;
char curarc[15];
struct stat stbuf;
/* First find out what archives we have out there for him */
sprintf (tmpjunk2, "%s%04x%04x.*", cur_dir,
config.net[1]-tonet, config.node[1]-tonode);
(void) filedir (tmpjunk2, 0, curarc, 0);
/* Lets be optimistic */
strcpy (arcext, asuffix[t2->tm_wday]);
/* Now if we have no archive to him, then just return the easy way */
if (curarc[0] == '\0')
{
printf ("Creating new archive '%s%04x%04x.%s'",
cur_dir, config.net[1]-tonet, config.node[1]-tonode, arcext);
if (cminternal)
{
printf ("\n");
}
else
{
printf ("and new MAIL:%04d.MSG\n", mail_high+1);
}
return (++mail_high);
}
strcpy (arcext, &curarc[9]);
sprintf (tmpjunk2, "%s%s", cur_dir, curarc);
find_old();
/* Now find if this node is in the list */
if (!cminternal)
{
for (i = 0; i < num_arc; i++)
{
if ((arc_node[i] == tonode) && (arc_net[i] == tonet))
{
/* We found an archive to this guy already */
if (del)
printf ("Adding to archive '%s' for node %d/%d (MAIL:%04d.MSG)\n",
tmpjunk2, tonet, tonode, arc_msg[i]);
return (arc_msg[i]);
}
}
arc_net[num_arc] = tonet;
arc_node[num_arc] = tonode;
arc_msg[num_arc] = ++mail_high;
++num_arc;
if (!del)
return (mail_high);
}
else
{
stat (tmpjunk2, &stbuf);
if (stbuf.st_size > 0)
{
if (del)
printf ("Adding to archive '%s' for node %d/%d\n",
tmpjunk2, tonet, tonode);
return (0);
}
}
/* No archive to him any more, delete the old archive */
printf ("Deleting SENT archive '%s'", tmpjunk2);
if (cminternal)
printf ("\n");
else
printf (" creating new MAIL:%04d.MSG\n", mail_high);
unlink (tmpjunk2);
/* Increment the new archive */
if (strncmp (arcext, asuffix[t2->tm_wday], 2) == 0)
{
if ((arcext[2] == '0') && (arc_compat))
{
arcext[2] = 'A';
}
else if (arcext[2] == '9')
{
arcext[2] = '0';
}
else if (arcext[2] == 'Z')
{
/* Oh well, take our chances and start again */
arcext[2] = '1';
}
else
{
++(arcext[2]);
}
}
else
strcpy (arcext, asuffix[t2->tm_wday]);
/* Return the easy way */
return (mail_high);
}
int set_bits (
int tonet,
int tonode,
unsigned int bits)
{
int needmsg, netdiff, nodediff, omailhigh;
char arcext[5];
/* set the bits used by the do_attach() routine */
def_attr = bits;
/* Now get the differences in net and node numbers to generate ARCmail */
netdiff = config.net[1] - tonet;
nodediff = config.node[1] - tonode;
printf ("Changing ARCmailing to %d/%d to %s/%s\n", tonet, tonode,
(bits&MSGCRASH)?"Crash":"NoCrash", (bits&MSGHOLD)?"Hold":"NoHold");
omailhigh = mail_high;
/* Find the extension to use */
if ((needmsg = suffix (tonet, tonode, arcext, 0)) > omailhigh)
{
mail_high = omailhigh;
printf ("No archive found for %d/%d\n", tonet, tonode);
return (0);
}
/* Create the new filename */
if (seahome)
sprintf (tmpjunk1, "%04x%04x.%s", netdiff, nodediff, arcext);
else
sprintf (tmpjunk1, "%s%04x%04x.%s", cur_dir, netdiff, nodediff, arcext);
/* create a file attach message */
do_attach (needmsg, tonet, tonode, tmpjunk1);
/* Return that all was ok */
return (0);
}
void find_old ()
{
int i, f;
char *t1;
char msgname[64];
if (cminternal)
return;
/* Otherwise we have to see if the mail was already sent */
if (num_arc == -1)
{
/* Mark that we executed this part already */
num_arc = 0;
/* Find all of the mail that has been sent */
printf ("Scanning for old ARCmail\n");
strcpy (msgname, config.mailpath);
t1 = msgname+strlen(msgname);
/* For each message in the netmail area */
for (i = 1; i <= mail_high; i++)
{
sprintf (t1, "\\%d.MSG", i);
/* If we can't open it then continue on */
if ((f = open (msgname, O_RDONLY|O_BINARY)) == -1)
continue;
/* Otherwise read in a message full */
if (fast_read (f, (char *) &msg_tmp, sizeof (MSG)) != sizeof (MSG))
{
/* If it is the wrong size, then continue */
(void) fast_close (f);
continue;
}
/* Close the file */
(void) fast_close (f);
/* If it does not have a file attached then continue */
if (!(msg_tmp.attr & MSGFILE))
continue;
/* If it is not to SysOp then continue */
if (strcmp (msg_tmp.to, "SysOp") != 0)
continue;
/* If it is not from ARCmail then continue */
if (strcmp (msg_tmp.from, "ARCmail") != 0)
continue;
/* If it is to us then continue */
if ((msg_tmp.dest == config.node[1]) && (msg_tmp.dest_net == config.net[1]))
continue;
/* Make sure it was generated here */
if (!(msg_tmp.attr & MSGLOCAL))
continue;
/* Otherwise save the pertinent data */
#if DEBUG
printf ("Found archive to %d/%d at message %d\n", msg_tmp.dest_net, msg_tmp.dest, i);
#endif
arc_net[num_arc] = msg_tmp.dest_net;
arc_node[num_arc] = msg_tmp.dest;
arc_msg[num_arc] = i;
++num_arc;
}
}
}
void zap_old ()
{
int i, f;
int j, k;
int tnet, tnode;
char nett[5], nodet[5];
char curarc[15];
char aname[64];
struct stat st_stat;
if (cminternal)
return;
/* Now clean out the old ARCmail by zapping it to 0 length */
printf("Zapping sent ARCmail to 0 length\n");
/* loop through *.SU? *.MO? ... */
for (i = 0; asuffix[i] != NULL; i++)
{
/* Set up the .....\*.MO? filename to look for */
sprintf (tmpjunk2, "%s*.%s", cur_dir, asuffix[i]);
tmpjunk2[strlen(tmpjunk2)-1] = '?';
(void) filedir (tmpjunk2, 0, curarc, 0);
k = 0;
while (curarc[0] != '\0')
{
++k;
/* Is it a real archive */
sprintf (aname, "%s%s", cur_dir, curarc);
if (stat (aname, &st_stat))
{
goto next_one;
}
if (strlen (curarc) != 12)
{
goto next_one;
}
if (arc_compat && !isdigit(curarc[11]))
{
goto next_one;
}
else if ((!arc_compat) && (!isalnum(curarc[11])))
{
goto next_one;
}
for (j = 0; j < 8; j++)
{
if ((curarc[j] <= '9') && (curarc[j] >= '0'))
continue;
if ((curarc[j] <= 'F') && (curarc[j] >= 'A'))
continue;
goto next_one;
}
if (st_stat.st_size > 0)
{
/* Each time we find something, see if it still has to go */
#ifndef IBMC
sscanf (curarc, "%04x%04x", &tnet, &tnode);
#else
sscanf (curarc, "%4s%4s", nett, nodet);
sscanf (nett, "%04x", &tnet);
sscanf (nodet, "%04x", &tnode);
#endif
tnet = config.net[1] - tnet;
tnode = config.node[1] - tnode;
/* Now find if this node is in the list */
for (j = 0; j < num_arc; j++)
{
if ((arc_node[j] == tnode) && (arc_net[j] == tnet))
{
break;
}
}
/* If not, then zap it down to 0 size */
if (j == num_arc)
{
printf ("Archive '%s' to %d/%d sent, ", aname, tnet, tnode);
unlink (aname);
if (i != t2->tm_wday)
{
printf ("deleting\n");
}
else
{
printf ("zapping\n");
f = open (aname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE);
fast_close (f);
}
/* Set up the .....\*.MO? filename to look for again */
sprintf (tmpjunk2, "%s*.%s", cur_dir, asuffix[i]);
tmpjunk2[strlen(tmpjunk2)-1] = '?';
--k;
for (j = 0; j < k; j++)
{
(void) filedir (tmpjunk2, j, curarc, 0);
}
}
}
/* Now get the next one */
next_one:
filedir (tmpjunk2, k, curarc, 0);
}
}
}